import { PartialType } from '@nestjs/swagger';
import {
  IsBoolean,
  IsDefined,
  IsNotEmpty,
  IsNumberString,
  IsOptional,
  MaxLength,
  ValidateIf,
} from 'class-validator';
import { isNil } from 'lodash';
import { DtoValidation } from 'src/decorators/custom-decorator';

@DtoValidation({ groups: ['create'] })
export class CreateMeetingRommDto {
  @IsNotEmpty({ groups: ['create'], message: '会议室名称必填' })
  @MaxLength(10, { message: '会议室名称长度不得超过$constraint1' })
  @IsOptional({ groups: ['update'] })
  name: string;

  @IsNumberString()
  @ValidateIf((value) => {
    return !isNil(value.capacity);
  })
  @IsNotEmpty({ groups: ['create'], message: '会议室容量为必填' })
  @IsOptional({ groups: ['update'] })
  capacity: number;

  @IsNotEmpty({ groups: ['create'], message: '会议室位置为必填' })
  @IsOptional({ groups: ['update'] })
  location: string;

  @IsNotEmpty({ groups: ['create'], message: '会议室设备为必填' })
  @IsOptional({ groups: ['update'] })
  equipment: string;

  @IsNotEmpty({ groups: ['create'], message: '会议室描述为必填' })
  @IsOptional({ groups: ['update'] })
  description: string;

  @IsBoolean({ always: true })
  @ValidateIf((value) => !isNil(value.isBooked))
  @IsNotEmpty({ groups: ['create'], message: '会议室是否被预定为必填' })
  @IsOptional({ groups: ['update'] })
  isBooked: boolean;
}
@DtoValidation({ groups: ['update'] })
export class UpdateMeetingRoom extends PartialType(CreateMeetingRommDto) {
  @IsDefined({ groups: ['update'], message: 'ID必须指定' })
  id: number;
}
